/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */

struct TreeNode
{
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};

class Solution
{
public:
    bool is_mirror(TreeNode *left, TreeNode *right)
    {
        if (!left && !right)
        { //都为空，
            return true;
        }
        else if ((left && !right) || (right && !left))
        { //一个空
            return false;
        }
        else
        {                                //都不空，
            if (left->val == right->val) //值相等
            {
                return is_mirror(left->left, right->right) && is_mirror(left->right, right->left);
            }
            else //值不等
            {
                return false;
            }
        }
    }
    bool isSymmetric(TreeNode *root)
    {
        //空，对称
        if (root == nullptr)
        {
            return true;
        }
        else
        {
            return is_mirror(root->left, root->right);
        }
    }
};